﻿package com.tudou.home.newskin.containers
{
    import com.tudou.home.newskin.buttons.*;
    import com.tudou.home.newskin.events.*;
    import com.tudou.skin.common.events.*;
    import com.tudou.utils.*;
    import flash.display.*;

    public class Volume extends Sprite implements IVolume, IShowWidthHeight
    {
        private var isVolumeOff:Boolean = false;
        private var volumeButton:VolumeButton;
        private var saveValue:Number = 1;
        private var volumeBar:VolumeBar;

        public function Volume()
        {
            volumeButton = new VolumeButton();
            volumeButton.y = 1;
            addChild(volumeButton);
            volumeBar = new VolumeBar();
            volumeBar.x = volumeButton.width + 2;
            addChild(volumeBar);
            volumeBar.addEventListener(BarEvent.START_DRAG, barHlr);
            volumeBar.addEventListener(BarEvent.DRAGING, barHlr);
            volumeBar.addEventListener(BarEvent.END_DRAG, barHlr);
            volumeButton.addEventListener(ButtonEvent.CLICK, buttonHlr);
            return;
        }// end function

        public function setMute(param1:Boolean) : void
        {
            isVolumeOff = param1;
            return;
        }// end function

        public function setVolume(param1:Number) : void
        {
            param1 = MathUtil.unit(param1);
            saveValue = param1;
            volumeBar.setValue(saveValue);
            volumeButton.isOn = param1 > 0;
            return;
        }// end function

        public function get showHeight() : uint
        {
            return 18;
        }// end function

        public function get showWidth() : uint
        {
            return 75;
        }// end function

        public function getMute() : Boolean
        {
            return isVolumeOff;
        }// end function

        public function getVolume() : Number
        {
            return volumeBar.getValue();
        }// end function

        private function barHlr(event:BarEvent) : void
        {
            var _loc_2:String = null;
            if (event.type == BarEvent.END_DRAG)
            {
                _loc_2 = SkinEvent.END_SET_VOLUME;
            }
            else
            {
                _loc_2 = SkinEvent.SET_VOLUME;
            }
            dispatchEvent(new SkinEvent(_loc_2, event.value));
            return;
        }// end function

        private function buttonHlr(event:ButtonEvent) : void
        {
            dispatchEvent(new SkinEvent(SkinEvent.MUTE, volumeButton.isOn));
            return;
        }// end function

    }
}
